import java.util.List;

/**
 * Created by loso on 2017/3/18.
 */
public class _67_AddBinary {

    public static void main(String[] args) {
        _67_AddBinary a = new _67_AddBinary();
        System.out.println(a.addBinary("110010","10111"));
    }

    public String addBinary(String a, String b) {
        StringBuilder sb = new StringBuilder();
        int cnt = 0;
        int len = a.length() > b.length()?a.length():b.length();
        a = new StringBuffer(a).reverse().toString();
        b = new StringBuilder(b).reverse().toString();
        for (int i = 0; i < len; i++) {
            if (i<a.length() && i<b.length()){
                if (a.charAt(i)=='1' && b.charAt(i)=='1'){
                    sb.append(0 + cnt);
                    cnt = 1;
                }
                else if (a.charAt(i)=='0' && b.charAt(i)=='0'){
                    sb.append(0 + cnt);
                    cnt = 0;
                }
                else {
                    sb.append(1 - cnt);
                }
                }
                else if(i<a.length()){
                if (a.charAt(i)=='0'){
                    sb.append(cnt);
                    cnt = 0;
                }
                else{
                    if (cnt == 1)
                        sb.append(0);
                    else{
                        sb.append(1);
                    }
                }
            }
            else{
                if (b.charAt(i)=='0'){
                    sb.append(cnt);
                    cnt = 0;
                }
                else{
                    if (cnt == 1)
                        sb.append(0);
                    else{
                        sb.append(1);
                    }
                }
            }
        }
        if (cnt == 1){
            sb.append(1);
        }
        return sb.reverse().toString();
    }
}
